/**
 * 订单路由
 * 定义订单相关的RESTful API路由
 */
const express = require('express');
const router = express.Router();
const OrderController = require('../controllers/order.controller');

// 注意路由顺序：具体路由在前，动态路由在后

/**
 * @swagger
 * /api/orders/goods/{goodsId}: 
 *   get: 
 *     summary: 获取立即购买商品信息
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: goodsId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 商品ID
 *       - in: query
 *         name: blessing
 *         schema:
 *           type: string
 *         description: 祝福语（可选）
 *     responses:
 *       200: 
 *         description: 获取成功
 */
router.get('/goods/:goodsId', OrderController.getImmediatePurchaseInfo);

/**
 * @swagger
 * /api/orders: 
 *   post: 
 *     summary: 提交订单
 *     tags: [订单管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               orderDetailList:
 *                 type: array
 *                 items:
 *                   type: object
 *                   properties:
 *                     goodsId:
 *                       type: integer
 *                     goodsName:
 *                       type: string
 *                     goodsPrice:
 *                       type: number
 *                     goodsCount:
 *                       type: integer
 *                     goodsImg:
 *                       type: string
 *                     goodsTotalPrice:
 *                       type: number
 *               totalAmount:
 *                 type: number
 *               totalNum:
 *                 type: integer
 *               userAddressId:
 *                 type: integer
 *               paymentWay:
 *                 type: string
 *     responses:
 *       200: 
 *         description: 下单成功
 */
router.post('/', OrderController.submitOrder);

/**
 * @swagger
 * /api/orders/{orderNo}/status: 
 *   patch: 
 *     summary: 更新订单状态
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               status:
 *                 type: integer
 *                 description: 新状态
 *     responses:
 *       200: 
 *         description: 更新成功
 */
router.patch('/:orderNo/status', OrderController.updateOrderStatus);

/**
 * @swagger
 * /api/orders/{orderNo}/pay: 
 *   patch: 
 *     summary: 支付订单
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 支付成功
 */
router.patch('/:orderNo/pay', OrderController.payOrder);

/**
 * @swagger
 * /api/orders/{orderNo}/ship: 
 *   patch: 
 *     summary: 发货
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 发货成功
 */
router.patch('/:orderNo/ship', OrderController.shipOrder);

/**
 * @swagger
 * /api/orders/{orderNo}/deliver: 
 *   patch: 
 *     summary: 确认收货
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 确认收货成功
 */
router.patch('/:orderNo/deliver', OrderController.deliverOrder);

/**
 * @swagger
 * /api/orders/{orderNo}/refund: 
 *   patch: 
 *     summary: 申请退款
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 申请退款成功
 */
router.patch('/:orderNo/refund', OrderController.initiateRefund);

/**
 * @swagger
 * /api/orders/{orderNo}/refund/complete: 
 *   patch: 
 *     summary: 完成退款
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 退款成功
 */
router.patch('/:orderNo/refund/complete', OrderController.completeRefund);

/**
 * @swagger
 * /api/orders/{orderNo}: 
 *   get: 
 *     summary: 获取订单详情
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: orderNo
 *         required: true
 *         schema:
 *           type: string
 *         description: 订单号
 *     responses:
 *       200: 
 *         description: 获取成功
 */
router.get('/:orderNo', OrderController.getOrderDetail);

/**
 * @swagger
 * /api/orders/{page}/{limit}: 
 *   get: 
 *     summary: 获取订单列表
 *     tags: [订单管理]
 *     parameters:
 *       - in: path
 *         name: page
 *         required: true
 *         schema:
 *           type: integer
 *         description: 页码
 *       - in: path
 *         name: limit
 *         required: true
 *         schema:
 *           type: integer
 *         description: 每页数量
 *       - in: query
 *         name: orderStatus
 *         schema:
 *           type: integer
 *         description: 订单状态（可选）
 *     responses:
 *       200: 
 *         description: 获取成功
 */
router.get('/:page/:limit', OrderController.getOrderList);

module.exports = router;